/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package travelmatching;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import au.com.bytecode.opencsv.CSVReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author dk
 */
public class Interface {
    final String MAINMENU = "Welcome to the TravelMatching Application \n To Login enter \"1\" \n To Register enter \"2\" \n At anytime to Exit enter \"exit\"";
    final String OPTQUE = "Please Enter what Option you would like to perform:";
    final String CLIENTOPT = "1)Find a Car-pooling match.\n2)Edit account information";
    final String ADMINOPT = "1) Add an Account.\n2) View/Edit Account Details.(Including Payments)\n3) Remove Account";
    final String CORPOPT = "1) Add an Account.";

    Interface(){

    }
    public void display(String out) {
        System.out.println(out);
    }
    public String getIn() {
        String in = new String();
        BufferedReader br = (new BufferedReader(new InputStreamReader(System.in)));
        try {
            in = br.readLine();
            if (in.equalsIgnoreCase("exit")) {
                System.exit(1);
            }
            return in;
        } catch (IOException ex) {
            Logger.getLogger("travelmatching.main").log(Level.SEVERE, null, ex);
        }
            
        return in;
    }
    String[] read(String userId) {
        CSVReader reader;
        List<String []> all;
        try {
            reader = new CSVReader(new FileReader("tmdb.csv"));
            all = reader.readAll();
            for (String[] i : all){
                if (i[0].equals(userId)){
                    return all.get(all.indexOf(i));
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger("travelmatching.main").log(Level.SEVERE, null, ex);
            FileWriter fstream;
            try {
                fstream = new FileWriter("tmdb.csv");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write("admin,admin,admin");
            } catch (IOException ex1) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex1);
            }

        } catch (IOException ex){
            Logger.getLogger("travelmatching.main").log(Level.SEVERE, null, ex);
        }
        return null;
    }
    void write(String in){
        FileWriter fstream;
            try {
                fstream = new FileWriter("tmdb.csv");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(in);
            } catch (IOException ex1) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex1);
            }
    }

    String inAccId() {
        display("Enter UserID:");
        return getIn();
    }

    String inPass() {
        display("Enter Password:");
        return getIn();
    }

    String [] getClientInfo() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    String [] newUsrInfo() {
        throw new UnsupportedOperationException("Not yet implemented");
    }


}
